package com.me.modules.sla.controller;

import java.util.List;

import com.me.modules.common.annotation.SysLog;
import com.me.modules.common.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.me.modules.sla.entity.SlaAlertDefEntity;
import com.me.modules.sla.service.SlaAlertDefService;
import com.me.modules.common.utils.Result;

import javax.servlet.http.HttpServletRequest;


/**
 * 服务级别协议告警策略定义
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-11 10:09:38
 */
@Controller
@RequestMapping("/sla/slaalertdef")
public class SlaAlertDefController extends BaseController{
	@Autowired
	private SlaAlertDefService slaAlertDefService;



	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@SysLog("查询工作时间模板")
	public String  list(SlaAlertDefEntity slaAlertDef, Model model , HttpServletRequest request){
		List<SlaAlertDefEntity> slaAlertDefList  = slaAlertDefService.queryListByBean(slaAlertDef);
		model.addAttribute("slaAlertDefList",slaAlertDefList);
		model.addAttribute("slaAlertDef",slaAlertDef);
		return "sla/sla_alert_def/list";
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info")
	//@RequiresPermissions("timetblinfo:info")
	@SysLog("查询工作时间列表")
	public String info( Model model,Long id, HttpServletRequest request){
		SlaAlertDefEntity slaAlertDef = slaAlertDefService.queryObject(id);
		model.addAttribute("slaAlertDef",slaAlertDef);
		return "sla/sla_alert_def/edit";
	}



	@RequestMapping(value = "save",method = RequestMethod.POST)
	//@RequiresPermissions("timetblinfo:save")
	@ResponseBody
	public Result save(SlaAlertDefEntity slaAlertDef){
		if(slaAlertDef.getId()==null) {
			slaAlertDefService.save(slaAlertDef);
		}else {
			slaAlertDefService.update(slaAlertDef);
		}
		return Result.ok().put("slaAlertDef",slaAlertDef);
	}



	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("slaalertdef:update")
	public Result update(@RequestBody SlaAlertDefEntity slaAlertDef){
		slaAlertDefService.update(slaAlertDef);

		return Result.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("slaalertdef:delete")
	public Result delete(@RequestBody Long[] ids){
		slaAlertDefService.deleteBatch(ids);

		return Result.ok();
	}

}
